<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>06.组件化-简单计数器案例</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="../lib/react.js"></script>
    <script src="../lib/react-dom.js"></script>
    <script src="../lib/babel.min.js"></script>
    <script type="text/babel">
      class ComputeNumber extends React.Component {
          constructor() {
              super();
              this.state = {
                  number: 1,
              }
              this.add = this.add.bind(this);
              this.sub = this.sub.bind(this)
          }

          add() {
              this.setState({
                  number: this.state.number + 1,
              })
          }

          sub() {
            const {}
              this.setState({
                  number: this.state.number - 1 >= 0 ? this.state.number - 1 : this.state.number,
              })
          }

          render() {
              return (
                  <div className="flex">
                      <button className="button" onClick={this.add}>+</button>
                      <div>{this.state.number}</div>
                      <button className="button" onClick={this.sub}>-</button>
                  </div>
              )
          }
      }

      const root = ReactDOM.createRoot(document.getElementById('root'));
      root.render(<ComputeNumber>我不会显示</ComputeNumber>)
    </script>
    <style>
      .flex {
        display: flex;
      }

      .button {
        cursor: pointer;
        margin: 4px;
      }
    </style>
  </body>
</html>
